Save Machine Learning Models
You can save the output of a learn and predict algorithm as a machine learning model. This stores the existing results and allows you to add the ML model to another data flow later on; this is useful if you want to apply the ML model to new data in the data flow. In this scenario, the algorithm will run faster because the previous results are stored. As the learn function was already run on the algorithm, only the predict function will run.
A saved ML model can be downloaded and used outside of Pyramid, or set as a target in the ETL in Pyramid.
- Click here to learn about learn and predict algorithms.
Save ML Model
Select this option to save the algorithm's output as a machine learning model.
To save an ML Model, select Save Model; name the ML model in the textbox below. Save and execute the master flow.
To use the saved ML model in another data flow, go to the Scripting tab and add the Scripting Model node to the data flow; it must be connected to a data set with the same structure (columns and data types) as the data set on which it was initially run.
From the Scripting Model node's Properties panel, go to the Scripting Model window. Under Model Type, choose Python. Under Model Name, select the saved ML model.
Download the Saved Model
To download the saved model, go to the Source Manager in Admin console; select the Machine Learning node from the data source tree, find the saved model (green arrow below), and click on the download button (red arrow).
In order to use the downloaded model outside of Pyramid, use the pickle package to load the data in the file as follows:
import pickle with open(path,'rb') as model_in: model = pickle.load(model_in)
Make sure that the Python environment’s packages’ versions used for the model’s training in Pyramid match the packages’ versions of the Python environment in which the model is being loaded.
Set As Target
This option is only enabled if you've selected Save Model in the Save ML Model window; choose this option to use the current scripting node as the target. In this scenario, the ETL data is not loaded into a database. As there's no ETL output, only the algorithm's learn and eval functions will run; the predict function will not run.
The ML model can then be connected to a different data flow, where the predict function will be run.
To use the Python node as the target, go to the Save ML Model window and select Save Model, then select Set as Target and name the model. Save and execute the master flow.
To use the saved ML model in another data flow, go to the Scripting tab and add the Scripting Model node to the data flow. The ML model can only be run if the data set has the same structure (columns and data types) as the data set on which the learn function was run.
From the Scripting Model node's Properties panel, go to the Scripting Model window. Under Model Type, choose Python. Under Model Name, select the saved ML model.